#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 1010;
char a[N][N];
bool st[N][N];
int n, m, ret;
int dir[8][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

bool check(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

void dfs(int x, int y) {
	st[x][y] = true;
	for(int i = 0; i < 8; ++ i ) {
		int dx = x + dir[i][0];
		int dy = y + dir[i][1];
		if(check(dx, dy) && !st[dx][dy] && a[dx][dy] == 'W') {
			dfs(dx, dy);
		}
	}
}
signed main() {
	IOS;
	cin >> n >> m;
	_for(i, 1, n) {
		_for(j, 1, m) {
			cin >> a[i][j];
		}
	}
	_for(i, 1, n) {
		_for(j, 1, m) {
			if(a[i][j] == 'W' && !st[i][j]) {
				ret++;
				dfs(i, j);
			}
		}
	}
	cout << ret << endl;
	return 0;
}



